
package flc.ast.adapter;

import android.view.View;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.ConvertUtils;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import flc.ast.R;
import flc.ast.bean.ApkBean;
import flc.ast.utils.MyUtils;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;

public class AppAdapter extends StkProviderMultiAdapter<ApkBean> {

    public AppAdapter() {
        addItemProvider(new StkSingleSpanProvider<>(82));
        addItemProvider(new AppProvider());
    }

    private class AppProvider extends BaseItemProvider<ApkBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_app;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, ApkBean bean) {
            baseViewHolder.setText(R.id.tvAppItemName, AppUtils.getAppName(bean.pkgName));
            baseViewHolder.setText(R.id.tvAppItemSize, ConvertUtils.byte2FitMemorySize(MyUtils.getAppSize(getContext(), bean.pkgName), 0));
            baseViewHolder.setImageDrawable(R.id.ivAppItemImg, AppUtils.getAppIcon(bean.pkgName));
            if (bean.isSelected()) {
                baseViewHolder.setImageResource(R.id.ivAppItemSel, R.drawable.ayxz);
            } else {
                baseViewHolder.setImageResource(R.id.ivAppItemSel, R.drawable.awxz);
            }
        }
    }


}
